<?php
require_once(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR ."core".DIRECTORY_SEPARATOR."functions.php");

class AdminController extends baseController
{
	private $events;
	private $activities;

	//@param : personId
	//@info : Constructor takes a person Id as parameter which creates an instance of that person object
	public function __construct($personId)
	{
		$this->person = new Person($personId);
	}

	//@info : checks if the person object is a valid admin or an event manager
	public function validateUser()
	{
		if(!$this->person->isAdmin() || !$this->person->isEvtMgr())
		{
			return false;
		}
		else
		{
			return true;
		}
	}

	//function to update user details
	public function updateUser($personId,$accountType,$firstName,$lastName,$email,$skills,$gender,$contactNumber,$address,$activated)
	{
		$person = new Person($personId);
		$person->updateProfile($firstName,$lastName,$accountType,$email,$skills,$gender,$contactNumber,$address,$activated);
		unset($person);
	}
    
    public function updateStaffId($personId,$staffId)
    {
        $person = new Person($personId);
		$person->updateStaffId($staffId);
		unset($person);
    }

	public function updateUniversityDetails($id,$universityId,$degreeName,$majors,$yod,$entryToUts,$highSchool,$eca,$scholarShips,$previousInternships,$internshipOrganized)
	{
		$pSon = new Person($id);
		$pSon->updateUniversityDetails($universityId,$degreeName,$majors,$yod,$entryToUts,$highSchool,$eca,$scholarShips,$previousInternships,$internshipOrganized);
		unset($pSon);
	}

	public function updateOtherDetails($id,$availaibity,$workshops,$driversLicence,$refugee,$indigenous,$paperwork,$contract,$offer)
	{
		$person = new Person($id);
		$person->updateOtherDetails($availaibity,$workshops,$driversLicence,$refugee,$indigenous,$paperwork,$contract,$offer);
		unset($person);
	}

	//function to create an event
	public function createEvent($eventName,$description,$startTime,$endTime,$startDate,$endDate,$meetingLocation,$locationDetails,$carpoolTime)
	{
		$cEvent = new createEvent($eventName,$description,$startTime,$endTime,$startDate,$endDate,$meetingLocation,$locationDetails,$carpoolTime);
		if($cEvent->register())
		{
			unset($cEvent);
			return true;
		}
		else
		{
			unset($cEvent);
			return false;
		}
	}

	public function createActivity($title,$startTime,$endTime,$startDate,$endDate,$description,$eventId)
	{
		$activity = new CreateActivity($title,$startTime,$endTime,$startDate,$endDate,$description,$eventId);
		if($activity->register())
		{
			unset($activity);
			return true;
		}
		else
		{
			unset($activity);
			return false;
		}
	}

	public function createRole($title,$description,$startTime,$endTime,$startDate,$endDate,$payRate,$activityId)
	{
		$role = new CreateRole($title,$description,$startTime,$endTime,$startDate,$endDate,$payRate,$activityId);
		if($role->register())
		{
			unset($role);
			return true;
		}
		else
		{
			unset($role);
			return false;
		}
	}

	public function deleteActivity($activityId)
	{
		/**
			@Pre_Condition : must delete all foreign keys from role
		*/
		return true;
	}

	public function deleteEvent($eventId)
	{
		/**
			@Pre_Condition : must delete all foreign keys from activity
		*/
		return true;
	}

	public function deleteRole($roleId)
	{
		/**
			@Pre_Condition : must delete all foreign keys from role_skill
		*/
	}

	public function getPersonsByType($var1,$var2=null,$var3=null)
	{
		return Person::getPersonsByType($var1,$var2,$var3);
	}

	public function getEventByDate($startDate)
	{
		return Event::getEventByDate($startDate);
	}

	public function getActivitiesByDate($startDate)
	{
		return Activity::getActivitiesByDate($startDate);
	}

	public function getRolesByDate($startDate)
	{
		return Role::getRolesByDate($startDate);
	}

	public function resetPassword($personId,$password)
	{
		return Person::resetPassword($personId,$password);
	}

	public function update($person=null,$fieldName,$value,$isInt = false)
	{
		if(is_null($person))
		{
			$this->person->update($fieldName,$value,$isInt);
		}
		else
		{
			$tmpPerson = new Person($person);
			$tmpPerson->update($fieldName,$value,$isInt);
			$tmpPerson = null;
			unset($tmpPerson);
		}
		
	}

	public function updateRoleApplied($personId,$roleId,$accepted,$hours,$attended)
	{
		Role::updateRoleAccepted($personId,$roleId,$accepted,$hours,$attended);
	}

}